package com.Final.hj;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class TaskJesksAdapter extends RecyclerView.Adapter<TaskJesksAdapter.ViewHolder> {

    private List<TaskJesksData> taskDatas;
    private final Context context;


    public class ViewHolder extends RecyclerView.ViewHolder {
        public CircleImageView header_image;
        public TextView task_uname;
        public TextView task_commit_content;
        public TextView task_commit_num;
        public TextView task_time;
        public ViewHolder(View itemView) {
            super(itemView);
            //此时我们可以获取每一项的控件实例
            header_image = (CircleImageView) itemView.findViewById(R.id.header_image);
            task_uname = (TextView) itemView.findViewById(R.id.task_uname);
            task_commit_content = (TextView) itemView.findViewById(R.id.task_commit_content);
            task_commit_num = (TextView) itemView.findViewById(R.id.task_commit_num);
            task_time = (TextView) itemView.findViewById(R.id.task_time);
        }
    }

    //数据的获取
    public TaskJesksAdapter(Context context, List<TaskJesksData> taskDatas) {
        this.context = context;
        this.taskDatas = taskDatas;
    }

    //获取布局实例
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.task_jesks_adapter,null);
        //返回布局文件的实例
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder viewHolder, final int i) {

        TaskJesksData dataItem = taskDatas.get(i);

        //设置相应的显示内容
        viewHolder.header_image.setImageResource(Integer.parseInt(dataItem.gethImgId()));
        viewHolder.task_uname.setText(dataItem.getUname());
        viewHolder.task_commit_content.setText(dataItem.getCommit());
        viewHolder.task_commit_num.setText(dataItem.getCommitNum());
        viewHolder.task_time.setText(dataItem.getTaskTime());

        //设置点击事件
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // 此时点击应该跳转到 相应的页面 并把id传递过去 拿取相应的数据
                Intent intent = new Intent(context, TaskJesksInfo.class);

                context.startActivity(intent);

            }
        });
    }

    //返回当前数据长度
    @Override
    public int getItemCount() {
        return taskDatas.size();
    }
}
